package com.oyjd.virtualdata;

import java.util.ArrayList;
import java.util.List;

import android.os.AsyncTask;

import com.oyjd.business.listview.vo.ListViewDemoVO;

public class VirtulData {
	private static String[] imgs = { "http://img4.cache.netease.com/cnews/2011/10/27/2011102708394525b82.jpg", "http://img5.cache.netease.com/travel/2011/10/20/20111020072117d4fb4.jpg", "http://img4.cache.netease.com/edu/2011/10/20/2011102007204188f87.jpg", "http://img4.cache.netease.com/lady/daisy/zhimei3/toutu10201.jpg", "http://img5.cache.netease.com/mobile/2011/10/19/2011101918402576345.jpg", "http://img5.cache.netease.com/cnews/2011/9/3/20110903105255197db.jpg", "http://img4.cache.netease.com/travel/2011/8/30/20110830070308ee998.jpg", "http://img4.cache.netease.com/cnews/2011/8/30/20110830071938a8e23.jpg", "http://img6.cache.netease.com/cnews/2011/8/31/2011083108080005380.jpg", "http://img6.cache.netease.com/cnews/2011/10/11/201110111826334ec82.jpg",
			"http://img6.cache.netease.com/cnews/2011/10/20/20111020005527fcf04.jpg", "http://img2.cache.netease.com/cnews/2011/12/24/201112240826249f9cc.jpg", "http://img2.cache.netease.com/game/2011/12/24/20111224141908d1942.jpg" };
	private static int picPos = 0;

	public VirtulData(DataBack dataBack) {
		this.dataBack = dataBack;
	}

	private DataBack dataBack;

	public interface DataBack {
		void back(List<ListViewDemoVO> data);
	}

	public void queryData(int type, int page, int pageSize) {
		queryData(type, page, pageSize, true);
	}

	public void queryData(final int type, final int page, final int pageSize, final boolean delayFlag) {
		new AsyncTask<Integer, Integer, List<ListViewDemoVO>>() {
			@Override
			protected List<ListViewDemoVO> doInBackground(Integer... params) {
				int maxNum = 0;
				switch (type) {
				case 1:
					maxNum = 43;
					break;
				case 2:
					maxNum = 2;
					break;
				case 3:
					maxNum = 34;
					break;
				}
				int first = (page - 1) * pageSize;
				int last = first + pageSize;
				if (last > maxNum) {
					last = maxNum;
				}

				List<ListViewDemoVO> list = new ArrayList<ListViewDemoVO>();
				for (int i = first; i < last; i++) {
					ListViewDemoVO vo = new ListViewDemoVO();
					switch (type) {
					case 1:
						vo.setName("阿基米德" + i);
						vo.setTitle("给我一个支点我将翘起地球");
						break;
					case 2:
						vo.setName("梦想" + i);
						vo.setTitle("没有梦想，人生将失去希望，生活将失去色彩");
						break;
					case 3:
						vo.setName("呐喊" + i);
						vo.setTitle("不在沉默中爆发，就在沉默中死亡！");
						break;
					}

					vo.setTime("时间:1886-05-13 09:43:21");
					vo.setPicUrl(imgs[picPos++ % imgs.length]);
					list.add(vo);
				}
				if (delayFlag) {
					try {
						Thread.sleep(1000L);
					} catch (InterruptedException e) {
					}
				}
				return list;
			}

			@Override
			protected void onPostExecute(List<ListViewDemoVO> obj) {
				dataBack.back(obj);
			}
		}.execute();

	}

}
